using System.Linq;
using System.ServiceModel.Syndication;
using aprogblog.App.MetaWeblog;
using aprogblog.Domain;
using aprogblog.Domain.Classes;
using aprogblog.Domain.Helpers;
using aprogblog.Specs.Helpers;
using FluentSpec;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace aprogblog.Specs {

    [TestClass]
    public class when_adding_an_Entry {
        
        static readonly Entry TheNewEntry = Actors.TheExpectedEntry;
        
        [TestClass]
        public class a_WeblogService : BehaviorOfWeblogService {
        
            readonly Post Post = default(Post);
            string TheResult;

            [TestInitialize]
            public override void SetUp() { 
                base.SetUp();
                Given.EntryFrom(Post).Is(TheNewEntry);
                TheResult = When.AddPost(null, null, null, Post, false);
            }
            
            [TestMethod]
            public void should_add_it_to_the_Blog() {
                
                Then.Blog.Should().Add(TheNewEntry);
            }
            
            [TestMethod]
            public void should_return_its_id() {
                
                TheResult.ShouldBe(TheNewEntry.Id);
            }
        }

        [TestClass]
        public class a_Blog : BehaviorOf<BlogClass> {
            
            [TestInitialize]
            public void SetUp() {
                Given.Feed.Is(new SyndicationFeed());
                When.Add(TheNewEntry);
            }
            
            [TestMethod]
            public void should_add_it_at_the_end() {
                
                Then.Feed.Items.Last().ToEntry().ShouldBe(TheNewEntry);
            }

            [TestMethod]
            public void should_store_it() {

                Should.Save();
            }
        }
    }
}